package com.shangxia.dog.commom.exce;

import com.shangxia.dog.commom.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.UUID;

/**
 * @author zhouya24
 * @date 2021/11/18 15:26
 * @apiNote 统一异常处理
 */

@Slf4j
@RestControllerAdvice("com.shangxia")
public class ComExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO<String> exceptionHandler(Exception e) {
        UUID uuid = UUID.randomUUID();
        log.info("统一异常处理 {} ", uuid.toString(), e);
        return ResultVO.error(uuid.toString() + "==" + e.getMessage());
    }

    @ExceptionHandler(value = BiException.class)
    @ResponseBody
    public ResultVO<String> myExceptionHandler(BiException e) {
        UUID uuid = UUID.randomUUID();
        log.info("统一异常处理 {} ", uuid.toString(), e);
        return ResultVO.error(uuid.toString() + "==" + e.getMessage());
    }
}
